/*
 * @Author: guojinxin_hub 1907745233@qq.com
 * @Date: 2024-06-14 09:35:19
 * @LastEditors: guojinxin_hub 1907745233@qq.com
 * @LastEditTime: 2024-10-09 09:39:15
 * @FilePath: \qintai-reservoir\vue.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const title = '永清县乡村一体化管理平台'

// 引入等比适配插件
const px2rem = require('postcss-px2rem')

// 配置基本大小
const postcss = px2rem({
  // 基准大小 baseSize，需要和rem.js中相同
  // remUnit: 14 代表 1rem = 14px; 所以当你一个14px值时，它会自动转成 (14px/14)rem
  remUnit: 16,
})
module.exports = {
  publicPath: '/',
  lintOnSave: true,

  devServer: {
    // 配置服务器
    open: true,
    // 项目运行时候的端口号
    port: 8080,
    // https: false,
    disableHostCheck: true,

    overlay: {
      warnings: true,
      errors: true,
    },
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8084/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '',
        },
      },
    },
  },
  css: {
    sourceMap: true, // 开启 CSS source maps
    loaderOptions: {
      sass: {
        prependData: "@import '@/styles/common.scss';",
      },
      postcss: {
        plugins: [postcss],
      },
    },
  },
  productionSourceMap: false,
  chainWebpack: (config) => {
    config.plugin('html').tap((args) => {
      args[0].title = title
      return args
    })
    if (process.env.NODE_ENV === 'production') {
      //生产包取消console debugger打印
      config.optimization.minimizer('terser').tap((args) => {
        args[0].terserOptions.compress.drop_console = true
        args[0].terserOptions.compress.drop_debugger = true
        args[0].terserOptions.compress.pure_funcs = ['console.log']
        args[0].terserOptions.output = {
          comments: false,
        }
        return args
      })
    }
    // 分析打包大小
    if (process.env.npm_config_report) {
      config
        .plugin('webpack-bundle-analyzer')
        .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
        .end()
    }
  },
  configureWebpack: {
    resolve: {
      extensions: ['.js', '.vue', '.json', '.ts', '.tsx'], // 加入ts 和 tsx
    },
  },
}
